package com.goodomen.garbage.web.web.controller.api;

import com.alibaba.fastjson.JSONObject;
import com.goodomen.garbage.service.api.DemoWebService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/demo")
@Slf4j
public class DemoController {

    @Resource
    private DemoWebService demoWebService;

    @GetMapping("/hello")
    public JSONObject demo() {
        log.info("访问demo/hello");
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("hello", "我是 web yeah!");
        return jsonObject;
    }

    @Value("${server.port}")
    String port;

    @GetMapping("/hi")
    public String Home(@RequestParam String name) {
        log.info("hi "+name+",i am garbage-web from port:" +port);
        // 通过 webService 调用 score （积分） 项目接口
        return "我是 web，我调用了 score，结果：" + demoWebService.sayHi(name);
    }
}
